home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / yelp / xslt / man2html.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2007-04-10  |  11.6 KB  |  411 lines

  1. <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
  2.  
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4.                 xmlns:yelp="http://www.gnome.org/yelp/ns"
  5.                 xmlns="http://www.w3.org/1999/xhtml"
  6.                 extension-element-prefixes="yelp"
  7.                 version="1.0">
  8.  
  9. <xsl:output method="html" encoding="UTF-8"/>
  10.  
  11. <xsl:include href="yelp-common.xsl"/>
  12.  
  13. <xsl:param name="stylesheet_path" select="''"/>
  14. <xsl:param name="linktrail"/>
  15.  
  16. <xsl:param name="yelp.javascript"/>
  17.  
  18. <xsl:param name="yelp.icon.blockquote"/>
  19. <xsl:param name="yelp.icon.caution"/>
  20. <xsl:param name="yelp.icon.important"/>
  21. <xsl:param name="yelp.icon.note"/>
  22. <xsl:param name="yelp.icon.programlisting"/>
  23. <xsl:param name="yelp.icon.tip"/>
  24. <xsl:param name="yelp.icon.warning"/>
  25.  
  26. <xsl:param name="yelp.color.fg"/>
  27. <xsl:param name="yelp.color.bg"/>
  28. <xsl:param name="yelp.color.anchor"/>
  29. <xsl:param name="yelp.color.rule"/>
  30. <xsl:param name="yelp.color.gray.fg"/>
  31. <xsl:param name="yelp.color.gray.bg"/>
  32. <xsl:param name="yelp.color.gray.bg.dark1"/>
  33. <xsl:param name="yelp.color.gray.bg.dark2"/>
  34. <xsl:param name="yelp.color.gray.bg.dark3"/>
  35. <xsl:param name="yelp.color.selected.fg"/>
  36. <xsl:param name="yelp.color.selected.bg"/>
  37. <xsl:param name="yelp.color.selected.bg.dark1"/>
  38. <xsl:param name="yelp.color.selected.bg.dark2"/>
  39. <xsl:param name="yelp.color.selected.bg.dark3"/>
  40. <xsl:param name="yelp.color.admon.fg"/>
  41. <xsl:param name="yelp.color.admon.bg"/>
  42. <xsl:param name="yelp.color.admon.bg.dark1"/>
  43. <xsl:param name="yelp.color.admon.bg.dark2"/>
  44. <xsl:param name="yelp.color.admon.bg.dark3"/>
  45.  
  46. <xsl:template match="Man">
  47.   <xsl:choose>
  48.     <xsl:when test="element-available('yelp:document')">
  49.       <yelp:document href="index">
  50.         <xsl:call-template name="html"/>
  51.       </yelp:document>
  52.     </xsl:when>
  53.     <xsl:otherwise>
  54.       <xsl:call-template name="html"/>
  55.     </xsl:otherwise>
  56.   </xsl:choose>
  57. </xsl:template>
  58.  
  59. <xsl:template name="html">
  60.   <html>
  61.     <head>
  62.       <title>
  63.         <xsl:value-of select="//TH/Title"/>
  64.       </title>
  65.       <style type="text/css">
  66.         <xsl:call-template name="html.css"/>
  67.       </style>
  68.       <script type="text/javascript">
  69.         <xsl:attribute name="src">
  70.           <xsl:value-of select="concat('file://', $yelp.javascript)"/>
  71.         </xsl:attribute>
  72.       </script>
  73.     </head>
  74.     <body>
  75.       <xsl:call-template name="html.linktrail"/>
  76.       <div class="body">
  77.         <xsl:apply-templates select="TH"/>
  78.         <xsl:apply-templates select="SH"/>
  79.       </div>
  80.     </body>
  81.   </html>
  82. </xsl:template>
  83.  
  84. <xsl:template name="html.css">
  85.   <xsl:call-template name="yelp.common.css"/>
  86.   <xsl:text>
  87.     div[class~="SH"] { margin-left: 1.2em; }
  88.     div[class~="SS"] { margin-left: 1.6em; }
  89.  
  90.     span[class~="R"] { font-family: serif; }
  91.     span[class~="Section"] { margin-left: 0.4em; }
  92.   
  93.     dd { padding-bottom: 10px; }
  94.   </xsl:text>
  95. </xsl:template>
  96.  
  97. <xsl:template name="html.linktrail">
  98.   <div class="linktrail" id="linktrail">
  99.     <xsl:call-template name="html.linktrail.one">
  100.       <xsl:with-param name="str" select="$linktrail"/>
  101.     </xsl:call-template>
  102.   </div>
  103. </xsl:template>
  104.  
  105. <xsl:template name="html.linktrail.one">
  106.   <xsl:param name="str"/>
  107.   <xsl:variable name="id" select="substring-before($str, '|')"/>
  108.   <xsl:variable name="post_id" select="substring-after($str, '|')"/>
  109.  
  110.   <span class="linktrail">
  111.     <a class="linktrail" href="x-yelp-toc:{$id}">
  112.       <xsl:choose>
  113.         <xsl:when test="contains($post_id, '|')">
  114.           <xsl:value-of select="substring-before($post_id, '|')"/>
  115.         </xsl:when>
  116.         <xsl:otherwise>
  117.           <xsl:value-of select="$post_id"/>
  118.         </xsl:otherwise>
  119.       </xsl:choose>
  120.     </a>
  121.   </span>
  122.  
  123.   <xsl:if test="contains($post_id, '|')">
  124.     <xsl:call-template name="html.linktrail.one">
  125.       <xsl:with-param name="str" select="substring-after($post_id, '|')"/>
  126.     </xsl:call-template>
  127.   </xsl:if>
  128. </xsl:template>
  129.  
  130. <!-- ======================================================================= -->
  131.  
  132. <xsl:template match="br">
  133.   <xsl:apply-templates/><br/>
  134. </xsl:template>
  135.  
  136. <!-- ignore anything in the Indent,Count,sp element for now -->
  137. <xsl:template match="Indent" />
  138. <xsl:template match="Count" />
  139. <xsl:template match="sp" />
  140.  
  141. <xsl:template match="B | fB">
  142.   <b><xsl:apply-templates/></b>
  143. </xsl:template>
  144.  
  145. <xsl:template match="CELL">
  146.   <td><xsl:apply-templates/></td>
  147. </xsl:template>
  148.  
  149. <xsl:template match="I | fI">
  150.   <i><xsl:apply-templates/></i>
  151. </xsl:template>
  152.  
  153. <xsl:template match="R | fR">
  154.   <span class="R"><xsl:apply-templates/></span>
  155. </xsl:template>
  156.  
  157. <xsl:template match="Verbatim">
  158.   <pre>
  159.     <xsl:choose>
  160.       <xsl:when test="node()[1]/self::text()">
  161.         <xsl:variable name="node" select="node()[1]"/>
  162.         <xsl:choose>
  163.           <xsl:when test="starts-with(string($node), ' ')">
  164.             <xsl:value-of select="substring-after(string($node), ' ')"/>
  165.             <xsl:apply-templates select="node()[position() != 1]"/>
  166.           </xsl:when>
  167.           <xsl:otherwise>
  168.             <xsl:value-of select="string($node)"/>
  169.             <xsl:apply-templates select="node()[position() != 1]"/>
  170.           </xsl:otherwise>
  171.         </xsl:choose>
  172.       </xsl:when>
  173.       <xsl:otherwise>
  174.         <xsl:apply-templates />
  175.       </xsl:otherwise>
  176.     </xsl:choose>
  177.   </pre>
  178. </xsl:template>
  179.  
  180. <xsl:template match="IP">
  181.   <xsl:choose>
  182.     <xsl:when test="preceding-sibling::*[1][self::IP]"/>
  183.     <xsl:otherwise>
  184.       <dl>
  185.         <xsl:apply-templates mode="IP.mode" select="."/>
  186.       </dl>
  187.     </xsl:otherwise>
  188.   </xsl:choose>
  189. </xsl:template>
  190.  
  191. <xsl:template mode="IP.mode" match="IP">
  192.   <dt>
  193.     <xsl:choose>
  194.       <xsl:when test="Tag">
  195.         <xsl:apply-templates select="Tag"/>
  196.       </xsl:when>
  197.       <xsl:otherwise>
  198.         <xsl:apply-templates/>
  199.       </xsl:otherwise>
  200.     </xsl:choose>
  201.   </dt>
  202.   <dd>
  203.     <xsl:apply-templates select="Tag/following-sibling::node()"/>
  204.   </dd>
  205.   <xsl:apply-templates mode="IP.mode"
  206.                        select="following-sibling::*[1][self::IP]"/>
  207. </xsl:template>
  208.  
  209. <xsl:template match="P">
  210.   <p><xsl:apply-templates/></p>
  211. </xsl:template>
  212.  
  213. <xsl:template match="ROW">
  214.   <tr><xsl:apply-templates/></tr>
  215. </xsl:template>
  216.  
  217. <xsl:template match="SS">
  218.   <xsl:variable name="nextSH" select="following-sibling::SH[1]"/>
  219.   <xsl:variable name="nextSS"
  220.                 select="following-sibling::SS[not($nextSH) or
  221.                                               following-sibling::SH[1] = $nextSH][1]"/>
  222.   <h3><xsl:apply-templates/></h3>
  223.   <div class="SS">
  224.     <xsl:choose>
  225.       <xsl:when test="$nextSS">
  226.         <xsl:apply-templates
  227.          select="following-sibling::*[following-sibling::SS[1] = $nextSS and 
  228.                                       following-sibling::SS[1]/@id = $nextSS/@id]"/>
  229.       </xsl:when>
  230.       <xsl:when test="$nextSH">
  231.         <xsl:apply-templates
  232.          select="following-sibling::*[following-sibling::SH[1] = $nextSH and
  233.                                       following-sibling::SH[1]/@id = $nextSH/@id]"/>
  234.       </xsl:when>
  235.       <xsl:otherwise>
  236.         <xsl:apply-templates select="following-sibling::*"/>
  237.       </xsl:otherwise>
  238.     </xsl:choose>
  239.   </div>
  240. </xsl:template>
  241.  
  242. <xsl:template match="SH">
  243.   <xsl:variable name="nextSH" select="following-sibling::SH[1]"/>
  244.   <xsl:variable name="nextSS"
  245.                 select="following-sibling::SS[not($nextSH) or
  246.                                               following-sibling::SH[1] = $nextSH]"/>
  247.   <h2><xsl:apply-templates/></h2>
  248.   <div class="SH">
  249.     <xsl:choose>
  250.       <xsl:when test="$nextSS">
  251.         <xsl:apply-templates
  252.          select="following-sibling::*[following-sibling::SS[1] = $nextSS[1] and
  253.                                       following-sibling::SS[1]/@id = $nextSS[1]/@id]"/>  
  254.         <xsl:apply-templates select="$nextSS"/>
  255.       </xsl:when>
  256.       <xsl:when test="$nextSH">
  257.         <xsl:apply-templates
  258.          select="following-sibling::*[following-sibling::SH[1] = $nextSH and
  259.                                       following-sibling::SH[1]/@id = $nextSH/@id]"/>
  260.       </xsl:when>
  261.       <xsl:otherwise>
  262.         <xsl:apply-templates select="following-sibling::*"/>
  263.       </xsl:otherwise>
  264.     </xsl:choose>
  265.   </div>
  266. </xsl:template>
  267.  
  268. <xsl:template match="TABLE">
  269.   <table><xsl:apply-templates/></table>
  270. </xsl:template>
  271.  
  272. <xsl:template match="Tag">
  273.   <span class="Tag"><xsl:apply-templates/></span>
  274. </xsl:template>
  275.  
  276. <xsl:template match="TH">
  277.   <h1>
  278.     <span class="Title">
  279.       <xsl:apply-templates select="Title/node()"/>
  280.     </span>
  281.     <span class="Section">
  282.       <xsl:text>(</xsl:text>
  283.       <xsl:apply-templates select="Section/node()"/>
  284.       <xsl:text>)</xsl:text>
  285.     </span>
  286.   </h1>
  287. </xsl:template>
  288.  
  289. <xsl:template match="UR">
  290.   <a>
  291.     <xsl:attribute name="href">
  292.       <xsl:value-of select="URI" />
  293.     </xsl:attribute>
  294.     <xsl:apply-templates/>
  295.   </a>
  296. </xsl:template>
  297.  
  298. <xsl:template match="URI"/>
  299.  
  300. <xsl:template match="UN">
  301.   <a name="text()" id="text()"/>
  302. </xsl:template>
  303.  
  304. <!-- these are all for mdoc (BSD) man page support -->
  305.  
  306. <!-- these are just printed out -->
  307. <xsl:template match="An | Dv | Er | Ev | Ic | Li | St">
  308.   <xsl:text>
  309. </xsl:text>
  310.   <xsl:apply-templates/>
  311. </xsl:template>
  312.  
  313. <!-- these are italicized -->
  314. <xsl:template match="Ad | Ar | Fa | Ot | Pa | Va | Vt">
  315.   <i><xsl:apply-templates/></i>
  316. </xsl:template>
  317.  
  318. <!-- these are bold -->
  319. <xsl:template match="Cd | Cm | Fd | Ic | Nm">
  320.   <b><xsl:apply-templates/></b>
  321. </xsl:template>
  322.  
  323. <!-- Function call - TODO need to do the ( , ) here -->
  324. <xsl:template match="Fn | Fo | Fc">
  325.   <i><xsl:apply-templates/></i>
  326. </xsl:template>
  327.  
  328. <!-- Cross reference -->
  329. <xsl:template match="Xr">
  330.   <xsl:variable name="manpage" select="substring-before(string(.), ' ')"/>
  331.   <xsl:variable name="section" select="substring-before(substring-after(string(.), ' '), ' ')"/>
  332.   <xsl:variable name="extra"   select="substring-after(substring-after(string(.), ' '), ' ')"/>
  333.   <a>
  334.     <xsl:attribute name="href">
  335.       <xsl:text>man:</xsl:text>
  336.       <xsl:value-of select="$manpage"/>
  337.       <xsl:text>(</xsl:text>
  338.       <xsl:value-of select="$section"/>
  339.       <xsl:text>)</xsl:text>
  340.     </xsl:attribute>
  341.     <xsl:value-of select="$manpage"/>
  342.     <xsl:text>(</xsl:text>
  343.     <xsl:value-of select="$section"/>
  344.     <xsl:text>)</xsl:text>
  345.   </a>
  346.   <xsl:value-of select="$extra"/>
  347. </xsl:template>
  348.  
  349. <!-- Option -->
  350. <xsl:template match="Op | Oo | Oc">
  351.   <xsl:text> [</xsl:text>
  352.   <xsl:apply-templates/>
  353.   <xsl:text>]</xsl:text>
  354. </xsl:template>
  355.  
  356. <!-- Trade or type name (small Caps). -->
  357. <xsl:template match="Tn">
  358.   <xsl:variable name="txt" select="string(child::text())"/>
  359.     <xsl:text> </xsl:text>
  360.     <xsl:value-of select="translate($txt, 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
  361.   <xsl:apply-templates select="*"/>
  362. </xsl:template>
  363.  
  364. <xsl:template match="Nd">
  365.   <xsl:text> - </xsl:text>
  366.   <xsl:apply-templates />
  367. </xsl:template>
  368.  
  369. <xsl:template match="Fl">
  370.   <xsl:text>-</xsl:text>
  371.   <b><xsl:apply-templates select="child::text()"/></b>
  372.   <xsl:apply-templates select="*"/>
  373. </xsl:template>
  374.  
  375. <xsl:template match="Bl">
  376.   <dl>
  377.     <xsl:for-each select="It">
  378.       <xsl:choose>
  379.         <xsl:when test="ItTag">
  380.           <dt><xsl:apply-templates select="ItTag"/></dt>
  381.           <dd>
  382.             <xsl:apply-templates select="ItTag/following-sibling::node()"/>
  383.           </dd>
  384.         </xsl:when>
  385.         <xsl:otherwise>
  386.           <dt>
  387.             <xsl:text>ΓÇó</xsl:text>
  388.           </dt>
  389.           <dd>
  390.             <xsl:apply-templates />
  391.           </dd>
  392.         </xsl:otherwise>
  393.       </xsl:choose>
  394.     </xsl:for-each>
  395.   </dl>
  396. </xsl:template>
  397.  
  398. <xsl:template match="ItTag">
  399.   <xsl:apply-templates/>
  400. </xsl:template>
  401.  
  402. <xsl:template match="*">
  403.   <xsl:message>
  404.     <xsl:text>Unmatched element: </xsl:text>
  405.     <xsl:value-of select="local-name(.)"/>
  406.   </xsl:message>
  407.   <xsl:apply-templates/>
  408. </xsl:template>
  409.  
  410. </xsl:stylesheet>
  411.